package com.wsc.springbootmultidevdemo.msg;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * MQ 连接帮助类
 */
public class ConnectionUtil {

    /**
     * 获得 MQ 连接
     * @return MQ 连接
     */
    public static Connection getConnection() throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        factory.setPort(5672);
        factory.setVirtualHost("testhost");
        factory.setUsername("admin");
        factory.setPassword("305617");

        //获得连接
        Connection connection = factory.newConnection();
        return connection;
    }

}
